package org.sword.wechat4j.driver.event;

import org.sword.wechat4j.driver.EventDriverI;
import org.sword.wechat4j.request.BaseEventMessage;
import org.sword.wechat4j.request.BaseMessage;
import org.sword.wechat4j.request.MenuViewEventMessage;
import org.sword.wechat4j.response.WechatResponse;
import org.sword.wechat4j.type.EventType;
import org.sword.wechat4j.type.MsgType;

/**
 * 菜单查看事件处理
 * Created by wxc on 2016/9/14.
 */
public abstract class ViewEventDriver extends EventDriverI {
    @Override
    public WechatResponse service(BaseMessage baseMessage) {
        WechatResponse response = super.service(baseMessage);
        if (!MsgType.event.name().equals(baseMessage.getMsgType())
                || !EventType.VIEW.name().equals(((BaseEventMessage)baseMessage).getEvent()))
            throw new RuntimeException("不是查看事件消息");
        handle((MenuViewEventMessage) baseMessage);
        return response;
    }

    protected abstract void handle(MenuViewEventMessage message);
}
